var config = require('../../config');
const userdataUrl = config.userdataUrl;
const adrnumUrl = config.adrnumUrl;

//获取应用实例
var app = getApp()
Page({
  data: {
    motto: 'Hello World',
    userInfo: {}
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  
  onLoad: function () {
    var that = this

    //调用应用实例的方法获取全局数据
    app.getUserInfo(function (userInfo) {      //更新数据
      that.setData({
        userInfo: userInfo
      })
      app.getUserOpenId(function (err, openid) {
        console.log(openid);
        if (!err) {
          var url = userdataUrl;
          console.log(openid);
          wx.request({
            data: {
              openid: openid,
              nickName: userInfo.nickName,
              gender: userInfo.gender,
              language: userInfo.language,
              city: userInfo.city,
              country: userInfo.country,
              province: userInfo.province,
              avatarUrl: userInfo.avatarUrl,
            },
            method: "post",
            url: url,
            success: function (e) {

            }
          })
          wx.request({
            url: adrnumUrl + openid, //仅为示例，并非真实的接口地址      
            header: {
              'content-type': 'application/json'
            },
            success: function (res) {
              that.setData({
                adnum: res.data
              })
            }
          })
        }
      })

    });

  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
    
    }
    return {
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },

/**
 * 收货地址
 */

  success:function (res) {
    console.log(res.userName)
    console.log(res.postalCode)
    console.log(res.provinceName)
    console.log(res.cityName)
    console.log(res.countyName)
    console.log(res.detailInfo)
    console.log(res.nationalCode)
    console.log(res.telNumber)
  }
})